package com.manager
{
	import com.engine.AwayEngine;
	import com.engine.PowerEngine;
	import com.model.CarDataRemote;
	import com.utils.PowerLoader;
	
	import flash.events.Event;
	import flash.geom.Vector3D;
	
	import away3d.lights.DirectionalLight;
	import away3d.lights.LightProbe;
	import away3d.lights.PointLight;
	

	public class CarSence
	{
		private static var cameraLight:PointLight;
		
		/*public static function ready():void{
			
		}*/
		private static var pointlight_0:PointLight;
		
		public static function start():void{
			PowerLoader.addCompleteEvent(loadComplete);
			if(PowerEngine.platform != PowerEngine.PLAT_PHONE)initLight();
		}
		
		/**
		 * 初始加载完成后 设置摄像头
		 * @param e
		 */		
		private static function loadComplete(e:Event):void
		{
			PowerLoader.removeCompleteEvent(loadComplete);
//			AwayEngine.setCamera(1500,1600,10,15,90,10);
			AwayEngine.setCamera(1300,1600,5,25,90,10);
//			AwayEngine.setCamera(1600,1600,3,20,130,9);
			AwayEngine.showStats = true;
		}
		
		private static function initLight():void
		{
//			var light:DirectionalLight = new DirectionalLight(0, -1, 0);
//			light.direction = new Vector3D();
//			light.color = 0xEEEEEE; 
//			var light:DirectionalLight = new DirectionalLight(-0.5, -1, -1);
//			light.ambient = 0.4;
//			light.color = 0xFFFFFF;
//			AwayEngine.addLight(light);
//			cameraLight = new PointLight();
//			cameraLight.color = 0xEEEEEE;
//			AwayEngine.addLight(cameraLight);
//			AwayEngine.addLoop(onLightMove);
			pointlight_0 = new PointLight();
			pointlight_0.name = "pointlight_0";
			pointlight_0.shaderPickingDetails = false;
			pointlight_0.ambientColor = 0xffffff;
			pointlight_0.z = 500;
			pointlight_0.x = 500;
			pointlight_0.castsShadows = false;
			pointlight_0.y = 500;
			pointlight_0.color = 0xcccccc;
			pointlight_0.diffuse = .2;
			pointlight_0.specular = .2;
			pointlight_0.zOffset = 0;
			pointlight_0.ambient = 1;
			
			var pointlight_1:PointLight = new PointLight();
			pointlight_1.name = "pointlight_1";
			pointlight_1.shaderPickingDetails = false;
			pointlight_1.fallOff = Number.MAX_VALUE;
			pointlight_1.ambientColor = 0xD9D9D9;
			pointlight_1.z = 17.221891350056694;
			pointlight_1.x = 49.889142934460324;
			pointlight_1.y = 1752.1292554736842;
			pointlight_1.castsShadows = false;
			pointlight_1.color = 0xEAEAEA;
			pointlight_1.diffuse = 0.5;
			pointlight_1.specular = .1;
			pointlight_1.zOffset = 0;
			pointlight_1.ambient = 0.1;
//			AwayEngine.addLight(pointlight_1);
			AwayEngine.addLight(pointlight_0);
			AwayEngine.addLoop(onLightMove);
//			var _lightProbe:LightProbe = new LightProbe(CarMaterial.getCubeTextures,CarMaterial.getCubeTextures);
//			_lightProbe.ambient = 1;
//			_lightProbe.color = 0;
//			_lightProbe.diffuse = 1;
//			_lightProbe.specular = 1;
//			_lightProbe.z = 17;
//			_lightProbe.x = 49;
//			_lightProbe.y = 17;
//			AwayEngine.camera.addChild(_lightProbe);
		}
		
		private static function onLightMove(e:Event):void
		{
			pointlight_0.position  = AwayEngine.camera.position;
		}
		
	}
}